package com.itshops.service.impl;

import com.itshops.dao.UserDao;
import com.itshops.dao.impl.UserDaoImpl;
import com.itshops.entity.User;
import com.itshops.service.UserService;
import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();
    @Override
    public boolean checkedUser(String username) throws SQLException {

        User user = userDao.selectUserByName(username);
        //处理返回值,user为空则返回false
        if (user != null) {
            return true;
        }
        return false;
    }

    @Override
    public int register(User user) throws SQLException {
        //用户信息保存
        int i = userDao.insertUser(user);


        return i;

    }

    @Override
    public User login(String username,String password) throws SQLException {
        //账号密码验证
        User user = userDao.selectUserByName(username);
        if (user!=null&&user.getUpassword().equals(password)){
            return user;
        }
        return null;
    }
}
